package com.wd.home.adapter

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import com.wd.common.bean.LookcarBean
import com.wd.home.R

/**
 * 作者：马海钊
 * 时间：2024/5/26 20:28
 * 功能：
 */
class HomeFindAdapter(
    val context: Context,
    private val list: List<LookcarBean.HomeFindBean.Result>,
    private val imglist: Array<Int>
) :
    RecyclerView.Adapter<HomeFindAdapter.ViewHolder>() {
    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        val view = LayoutInflater.from(context).inflate(R.layout.item_homefind, parent, false)
        return ViewHolder(view)
    }

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        holder.name.setText(list.get(position).name)
        Glide.with(holder.itemView.context)
            .load(imglist.get(position))
            .placeholder(R.mipmap.ic_launcher)
            .error(R.mipmap.ic_launcher)
            .into(holder.price)
//        holder.itemView.setOnClickListener {
//            if (holder != null) {
//                context.startActivity(Intent(context, HomePaiHangActivity::class.java))
//            }
//        }
    }

    override fun getItemCount(): Int {
        return list.size
    }

    inner class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
        val name: TextView = itemView.findViewById(R.id.item_homefind_name)
        val price: ImageView = itemView.findViewById(R.id.item_homefind_price)

    }

}